import { View, Text } from '@tarojs/components'
import './index.scss'
import { useState } from 'react'
import Taro from '@tarojs/taro'
import { AtForm, AtInput, AtButton } from 'taro-ui'
import request  from '../../utils/request'
export default function Index () {
  
  const [loginform,setloginform] = useState({
    username:'',
    password:''
  }) 
  const submit = ()=>{
    //admin/login
    request.post('admin/login',loginform).then((res)=>{
      console.log(res);
      Taro.setStorage({
        key:"token",
        data:res.token
      })
      Taro.navigateTo({url:'/pages/my/index'})
    })
  }
  return (
    <div className='loginform'>
      <AtForm>
        <AtInput 
          name='value' 
          title='账号' 
          type='text' 
          placeholder='账号' 
          value={loginform.username} 
          onChange={(v)=>{setloginform({
            ...loginform,
            ...{
              username:v
            }
          })}}
        />
        <AtInput 
          name='value' 
          title='密码' 
          type='password' 
          placeholder='密码' 
          value={loginform.password} 
          onChange={(v)=>{setloginform({
          ...loginform,
          ...{
            password:v
          }
        })}}
        />
        <AtButton formType='submit' className='loginbutton' onClick={submit}>登录</AtButton>
        
      </AtForm>
      <div className='toreg' onClick={()=>Taro.navigateTo({url:'/pages/register/index'})}>
          <a>暂无账号?去注册</a>
        </div>
    </div>
    
  )
}
